package edu.wuster.blog.mapper;

import edu.wuster.blog.entity.Comment;
import edu.wuster.blog.entity.Reply;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import java.util.List;

@Mapper
public interface CommentMapper {

    @Insert("insert into comment(username,blog_id, text,create_time) values (#{username},#{blogId},#{text},#{createTime})")
    void addComment(Comment comment);

    @Insert("insert into reply(comment_id,username,text,create_time) values (#{commentId},#{username},#{text},#{createTime})")
    void addReply(Reply reply);


    @Select("select * from comment where blog_id = #{blogId} ")
    List<Comment> selectByBlogId(Integer blogId);

    @Select("select * from reply where comment_id = #{commentId} ")
    List<Reply> selectReply(Integer commentId);


    //根据评论ID查找评论，用于存在判断
    @Select("select * from comment where id = #{commentId} ")
    List<Reply> selectByCommentID(Integer commentId);


}
